package pers.fengxu.learnmybatis.type;

import java.math.BigDecimal;

public class TypeHandler {
    public static Object convertValue(Class<?> clazz, String value) {
        if (clazz == Integer.class || clazz == int.class) {
            return Integer.valueOf(value);
        }
        if (clazz == String.class) {
            return value;
        }
        if (clazz == Long.class || clazz == long.class) {
            return Long.valueOf(value);
        }
        if (clazz == Boolean.class || clazz == boolean.class) {
            return Boolean.valueOf(value);
        }
        if (clazz == Byte.class || clazz == byte.class) {
            return Byte.valueOf(value);
        }
        if (clazz == Short.class || clazz == short.class) {
            return Short.valueOf(value);
        }
        if (clazz == Character.class || clazz == char.class) {
            return value.charAt(0);
        }
        if (clazz == Float.class || clazz == float.class) {
            return Float.valueOf(value);
        }
        if (clazz == Double.class || clazz == double.class) {
            return Double.valueOf(value);
        }
        if (clazz == BigDecimal.class) {
            return new BigDecimal(value);
        }
        return null;
    }
}
